package com.study.springboottest.design.singleton;

public class Mgr07 {

    private Mgr07() {
    }

    /**
     * 在Mgr07初始化加载时,内部类不会加载
     * 线程安全是虚拟机保证的---类加载时只加载一次
     * 因此,内部类只加载一次
     */
    private static class Mgr07Holder {
        private static final Mgr07 INSTANCE = new Mgr07();
    }

    public static Mgr07 getInstance() {
        return Mgr07Holder.INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                System.out.println(Mgr07.getInstance().hashCode());
            }).start();
        }
    }
}
